
def RunHook(hi, logger):
  """Implements gvn.hooks.runner's RunHook interface

  Returns:
    -1: pass and bypass other hooks
    0: pass
    1: fail
    "string": fail and print string to the user
  """
  cbp = hi.project_config['change-branch-base'] + '/'
  prefix = hi.prefix_changed

  # Example with cbp == 'changes/':
  #   prefix                                    => (left, right)
  #   ----------------------------------------------------------------
  #   'trunk'                                   => ValueError
  #   'project/changes/foo'                     => ('project/', 'foo')
  #   'changes/basil'                           => ('', 'basil')
  #   'changes/basil/foo/trunk/doc/changes/foo' => ('', 'basil/foo/trunk/doc/changes/foo')
  try:
    (left, right) = prefix.split(cbp, 1)
  except ValueError:
    # Not a changebranch, so we don't care about it.
    return 0
  if left != '':
    # Not a changebranch, so we don't care about it.
    return 0

  # Got a changebranch, and the owner is everything in right before the /
  cb_area_owner = right.split('/')[0]
  if cb_area_owner != hi.author:
    return "%s cannot commit to %s's changebranch area" % (hi.author,
                                                           cb_area_owner)
  return 0
